-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Fix RegexParser to ignore vertical tabs with RegexOptions.IgnorePatternWhitespace #120625
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: stephentoub <[email protected]>
src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/Regex.Match.Tests.cs
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a bug in the regex parser where vertical tab (\v
, character 0xB) was not being treated as whitespace when using RegexOptions.IgnorePatternWhitespace
, making it inconsistent with other .NET APIs and regex engines like PCRE2.
- Updated the ASCII character category table to mark vertical tab as whitespace
- Added vertical tab to the metacharacters SearchValues for proper escaping
- Added test case to verify vertical tab is properly ignored with IgnorePatternWhitespace option
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
File | Description |
---|---|
RegexParser.cs | Updated character category table to treat vertical tab as whitespace and added \v to metacharacters |
Regex.Match.Tests.cs | Added test case verifying vertical tab is ignored with IgnorePatternWhitespace option |
Co-authored-by: stephentoub <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Fix: Regex parser to ignore vertical tabs in pattern with RegexOptions.IgnorePatternWhitespace
Plan:
\v
, 0xB) is not ignored with IgnorePatternWhitespaceChanges Made:
\v
to s_metachars SearchValuesif (!PlatformDetection.IsNetFramework)
to prevent failures on .NET FrameworkTest Results:
✅ FunctionalTests: 29,291 tests passed, 0 failures
✅ UnitTests: 1,005 tests passed, 0 failures
✅ New test case: Verified passing across all regex engines (Interpreter, Compiled, NonBacktracking, SourceGenerated) on .NET Core
Technical Details:
Original prompt
Fixes #73206
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.